package com.tedu.interceptor.config;

import com.tedu.interceptor.interceptor.MyInterceptor;
import com.tedu.interceptor.interceptor.MyInterceptor2;
import com.tedu.interceptor.interceptor.MyInterceptor3;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class Config implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截器
        //默认全部拦截
        /*registry.addInterceptor(new MyInterceptor());*/

        //可以为拦截器指定拦截路径
        /*registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/users/reg");*/
            //可以指定多个
        /*registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/users/reg","/users/login");*/
            //可以进行模糊匹配
        /*registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/users/**");*/
            //可以排除
        /*registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/users/**")
                .excludePathPatterns("/users/login");*/

        registry.addInterceptor(new MyInterceptor());
        registry.addInterceptor(new MyInterceptor2());
        registry.addInterceptor(new MyInterceptor3());
    }
}
